package beans;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;

public class SprintItemBean {
	private int id;
	private int projectId;
	private String name;
	private String description;
	private String startDate;
	private String endDate;
	private List<UserStoryBean> userStories = new ArrayList<UserStoryBean>();
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public int getProjectId() {
		return projectId;
	}
	
	public void setProjectId(int projectId) {
		this.projectId = projectId;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getStartDate() {
		return startDate;
	}
	
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}
	
	public String getEndDate() {
		return endDate;
	}
	
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	
	public List<UserStoryBean> getUserStories() {
		return userStories;
	}

	public void setUserStories(List<UserStoryBean> userStories) {
		this.userStories = userStories;
	}

	public void addUserStory(UserStoryBean userStory) {
		userStories.add(userStory);
	}
	
	public String getJson() {
		StringBuffer sb = new StringBuffer();
		Gson gson = new Gson();
		
		sb.append("{");
		sb.append("\"sprint_id\": " + gson.toJson(id) + ",");
		sb.append("\"project_id\": " + gson.toJson(projectId) + ",");
		sb.append("\"name\": " + gson.toJson(name) + ",");
		sb.append("\"description\": " + gson.toJson(description) + ",");
		sb.append("\"start_date\": " + gson.toJson(startDate) + ",");
		sb.append("\"end_date\": " + gson.toJson(endDate) + ",");
		sb.append("\"user_story\": [");

		for (int j = 0; j < userStories.size(); j++) {
			UserStoryBean userStory = userStories.get(j);
			sb.append(userStory.getJson());
			
			if (j != userStories.size() - 1) {
				sb.append(",");
			}
		}
		sb.append("]");
		sb.append("}");

		return sb.toString();
	}
}
